package com.example.administrator.k3xiangmu.adapter;

import android.content.Context;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.Button;
import android.widget.TextView;

import com.example.administrator.k3xiangmu.R;
import com.example.administrator.k3xiangmu.entity.RukuEntity;
import com.example.administrator.k3xiangmu.entity.Saomiao2Entity;

import java.security.spec.PSSParameterSpec;
import java.util.List;

import de.greenrobot.event.EventBus;

/**
 * Created by Administrator on 2017-02-08.
 */
public class RukuAdapter extends BaseAdapter {
    private List<RukuEntity> list;
    private Context context;

    @Override
    public int getCount() {
        return list.size();
    }

    public RukuAdapter(List<RukuEntity> list, Context context) {
        this.list = list;
        this.context = context;
    }

    @Override
    public Object getItem(int position) {
        return list.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(final int position, View convertView, ViewGroup parent) {
        Holder holder;
        if(convertView==null){
            convertView=View.inflate(context, R.layout.item_saomiao2,null);
            holder=new Holder();

            holder.tv=(TextView) convertView.findViewById(R.id.no);
            holder.tv2=(TextView) convertView.findViewById(R.id.nu);
            holder.tv3=(TextView) convertView.findViewById(R.id.ck);
            holder.tv4=(TextView) convertView.findViewById(R.id.price);
            holder.bt=(Button)convertView.findViewById(R.id.bt);
            convertView.setTag(holder);
        }else {
            holder=(Holder) convertView.getTag();
        }
        holder.tv.setText(list.get(position).getName());
        holder.tv2.setText(list.get(position).getNumber()+"");
        holder.tv3.setText(list.get(position).getCkname());
        holder.tv4.setText(list.get(position).getPrice()+"");
        holder.bt.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                EventBus.getDefault().post(list.get(position));
                list.remove(position);

                notifyDataSetChanged();
            }
        });
        return convertView;
    }
    class Holder{
        private TextView tv,tv2,tv3,tv4;
        private Button bt;

    }
}
